package com.sn.system.common.validator.validators;

import java.util.Date;

import com.sn.system.common.constants.Constants;

import com.opensymphony.xwork2.validator.ValidationException;
import com.opensymphony.xwork2.validator.validators.FieldValidatorSupport;

public class DateRangeValidator extends FieldValidatorSupport{

	private String toDate;
	public void validate(Object object) throws ValidationException {
		 String fieldName = getFieldName();
	        Object val1 = this.getFieldValue(fieldName, object);
	        Object val2=this.getFieldValue(toDate, object);
	        
	        if (val1 == null ) {
	            return;
	        }
	        if (val2 == null ) {
	            return;
	        }
	        
	        // XW-375 - must be a string
	        if (!(val1 instanceof Date)||!(val2 instanceof Date)) {
	            return;
	        }
	        
	        Date from=(Date)val1;
	        Date to=(Date)val2;

	        if(from.getTime()>to.getTime()){
	        	addFieldError(fieldName, object);
		        return;
	        }
		
	}
	public String getToDate() {
		return toDate;
	}
	public void setToDate(String toDate) {
		this.toDate = toDate;
	}
	
	
}
